{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import nltk\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "seed = 1024\n",
    "np.random.seed(seed)\n",
    "\n",
    "path = '../data/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = pd.read_pickle(path + \"train_clean.pkl\")\n",
    "valid = pd.read_pickle(path + \"valid_clean.pkl\")\n",
    "dev = pd.read_pickle(path+'dev_clean.pkl')\n",
    "\n",
    "\n",
    "data_all = pd.concat([train,valid,dev])\n",
    "data_all.reset_index(inplace=1,drop=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def get_pos_tag(cx):\n",
    "    wl = str(cx).lower().split()\n",
    "    pos_l = nltk.pos_tag(wl)\n",
    "    q1_pos = []\n",
    "    for pos in pos_l:\n",
    "        q1_pos.append(pos[1])\n",
    "    return q1_pos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['IN',\n",
       " 'JJS',\n",
       " 'NNS',\n",
       " 'VBP',\n",
       " 'VBP',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'NN',\n",
       " 'VBD',\n",
       " 'RB',\n",
       " 'RB',\n",
       " 'JJR',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'CC',\n",
       " 'RB',\n",
       " 'IN',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " ':',\n",
       " ':',\n",
       " 'PRP',\n",
       " 'VBZ',\n",
       " 'JJ',\n",
       " 'JJ',\n",
       " 'JJ',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'CC',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'VBD',\n",
       " 'VBG',\n",
       " 'NNS',\n",
       " 'NN',\n",
       " 'VBD',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'TO',\n",
       " 'VB',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'CC',\n",
       " 'JJ',\n",
       " 'VBP',\n",
       " 'VB',\n",
       " 'NN',\n",
       " 'VBG',\n",
       " 'JJ',\n",
       " 'TO',\n",
       " 'VB',\n",
       " 'PRP',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'VBZ',\n",
       " 'VBN',\n",
       " 'CC',\n",
       " 'VBZ',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'NNS',\n",
       " 'DT',\n",
       " 'NNS',\n",
       " 'VBZ',\n",
       " 'JJ',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'NN',\n",
       " 'NN',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'VBZ',\n",
       " 'JJ',\n",
       " 'CC',\n",
       " 'PRP$',\n",
       " 'NN',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'VBZ',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'VBD',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'RB',\n",
       " 'VBZ',\n",
       " 'VBN',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'IN',\n",
       " 'RB',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'IN',\n",
       " 'NNS',\n",
       " 'CC',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'NN',\n",
       " 'CC',\n",
       " 'IN',\n",
       " 'JJ',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'NN',\n",
       " 'VBG',\n",
       " 'NN',\n",
       " 'PRP',\n",
       " 'MD',\n",
       " 'VB',\n",
       " 'RB',\n",
       " 'JJ',\n",
       " 'TO',\n",
       " 'VB',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'RB',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'NN',\n",
       " 'VBD',\n",
       " 'VBN',\n",
       " 'VBN',\n",
       " 'IN',\n",
       " 'DT',\n",
       " 'JJ',\n",
       " 'NN']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_pos_tag(data_all['context'][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  5%|▍         | 1431/30920 [00:33<10:16, 47.87it/s]"
     ]
    }
   ],
   "source": [
    "pos_fea = np.zeros((data_all.shape[0],2))\n",
    "dd =data_all['context'].values\n",
    "for it in tqdm(np.arange(data_all.shape[0])):\n",
    "    pos_ = get_pos_tag(dd[it])\n",
    "    pos_fea[it,0] = len(pos_)\n",
    "    pos_fea[it,1] = len(set(pos_))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
